var ECharts;
$(document).ready(function () {

    require.config({
        baseUrl: ctx + '/resource/plugins/echarts4',
        paths: {
            echarts: 'echarts',
            roma: 'theme/roma',

        }
    });
    require(
        [
            'echarts',
            'roma'
        ],
        function (ec) {
            ECharts = ec;
            host_cpu_syl_zxt = ECharts.init(document.getElementById('host_cpu_syl_zxt'), 'roma');
            queryHostCpu();
        }
    );
});


function queryHostCpu() {
    $.ajax({
        url: ctx + "/queryTime/targetFileSystemQuery",
        type: "post",
        data: "KPI_ID=" + KPI_ID + "&EXT_UNIT_ID=" + EXT_UNIT_ID + "&START=" + START + "&END=" + END + "&SELECT=" + SELECT,
        success: function (data) {
            var list = JSON.parse(data);
            var xdata = [];
            var ydata1 = [];
            var x_value = [];
            if (SELECT == "showTime") {
                for (var i = 0; i < list.length; i++) {
                    x_value = list[i].UNIT_ID.substring(list[i].UNIT_ID.lastIndexOf("-") + 1);
                    xdata.push(x_value);
                    ydata1.push(list[i].AVG_VALUE);
                }
            } else if (SELECT == "showMonth") {
                for (var i = 0; i < list.length; i++) {
                    // x_value = list[i].DATA_TIME.split("-");
                    // xdata.push(x_value[2]);
                    x_value = list[i].UNIT_ID.substring(list[i].UNIT_ID.lastIndexOf("-") + 1);
                    xdata.push(x_value);
                    ydata1.push(list[i].AVG_VALUE);
                }
            } else {
                for (var i = 0; i < list.length; i++) {
                    x_value = list[i].UNIT_ID.substring(list[i].UNIT_ID.lastIndexOf("-") + 1);
                    xdata.push(x_value);
                    ydata1.push(list[i].AVG_VALUE);
                }
            }
            option = {
                tooltip: {
                    trigger: 'axis',
                },
                legend: {
                    formatter: function (series) {
                        return series;
                    },
                    // data: ['使用率'],
                    textStyle: {
                        color: '#AAAAAA'
                    }
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: [{
                    type: 'category',
                    boundaryGap: false,
                    axisLabel: {
                        /*formatter:'{value} h',*/
                        textStyle: {
                            color: '#AAAAAA'
                        }
                    },
                    data: xdata
                }],
                yAxis: [{
                    type: 'value',
                    max: 100,//Y轴最大值 不写的话自动调节
                    axisLabel: {
                        formatter: '{value} %',
                        textStyle: {
                            color: '#AAAAAA'
                        }
                    }
                }],
                series: [
                    {
                        name: KPI_NAME,
                        type: 'line',
                        // color: '#EFB700',//黄
                        color: '#FF0A0E',//红
                        // color: '#0AFFBD',//蓝
                        data: ydata1
                    },
                ]
            };
            host_cpu_syl_zxt.setOption(option);
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}
